package com.zhs.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;


public class RabbitUtils {
    //连接工厂
    private static ConnectionFactory connectionFactory = new ConnectionFactory();
    static {
        //设置主机
        connectionFactory.setHost("124.222.199.186");
        //端口号
        connectionFactory.setPort(5672);//5672是RabbitMQ的默认端口号
        //用户名
        connectionFactory.setUsername("123456");
        //密码
        connectionFactory.setPassword("123456");
        //设置虚拟机,相当于数据库
        connectionFactory.setVirtualHost("/study_mq");
    }
    public static Connection getConnection(){
        Connection conn = null;
        try {
            //获取长连接
            conn = connectionFactory.newConnection();
            return conn;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
